﻿using SHomeWorkshop.LunarPresentation.Dialogs;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void Comment(MainWindow window)
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt != null)
            {
                Command.EditBaseText(bt, null, true);
                return;
            }

            string text = string.Empty;
            if (Globals.selectedEditor.SelectedExpression.CommentText != null)
            {
                text = Globals.selectedEditor.SelectedExpression.CommentText;
            }

            InputWindow iw = new InputWindow(window, "请输入公式备注文本：", text, Globals.appName) { Owner = Globals.MainWindow };
            Globals.SwitchInputMethod(true);

            if (iw.ShowDialog() == true)
            {
                Expressions.Expression ex = Globals.selectedEditor.SelectedExpression;
                ModifingItem mi = new ModifingItem();
                Action action = new Action(ex.ExID,
                    -1, ex.GetType().Name, "CommentText", ex.CommentText, iw.InputedText);
                Globals.selectedEditor.SelectedExpression.CommentText = iw.InputedText;
                mi.Add(action);
                ex.Editor.Do(mi);
            }

            Globals.SwitchInputMethod(false);
        }
    }
}
